﻿/*
*VMukti -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, VMukti Solutions Pvt. Ltd.
*
* Hardik Sanghvi <hardik@vmukti.com>
*
* See http://www.vmukti.com for more information about
* the VMukti project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls; 
using System.Windows.Interop;
using Microsoft.Win32;
using VMukti.Business;
using VMukti.Business.WCFServices.BootStrapServices.DataContracts;
using VMukti.Business.WCFServices.SuperNodeServices.BasicHttp;
using VMukti.Business.WCFServices.SuperNodeServices.DataContract;
using VMuktiAPI;
using System.Windows.Input;
using System.Windows.Data;
using System.Text;

namespace VMukti.Presentation.Controls
{
	public partial class CtlLogin : System.Windows.Controls.UserControl, IDisposable
	{
		private clsRTCAuthClient objRTCAuthClient = null;

		public delegate void DelAutherized();
		public event DelAutherized EntAutherized = null;
        System.Text.StringBuilder sb1 = new System.Text.StringBuilder();

		clsSuperNodeDataContract objSuperNodeDataContract = null;

		TextBox txtEmail = new TextBox();
		System.Windows.Threading.DispatcherTimer dispTimer4DomainLoading = new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Normal);

		public CtlLogin()
		{
			try
			{
				this.InitializeComponent();

				this.Loaded += new RoutedEventHandler(CtlLogin_Loaded);

				dispTimer4DomainLoading.Tick += new EventHandler(dispTimer4DomainLoading_Tick);
				dispTimer4DomainLoading.Interval = TimeSpan.FromSeconds(1);
				txtEmail.KeyDown += new KeyEventHandler(txtEmail_KeyDown);

               

			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "CtlLogin()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}


		void CtlLogin_Loaded(object sender, RoutedEventArgs e)
		{
            try
            {
                if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri.AbsoluteUri.ToString().Contains("?"))
                {
                    string[] str = (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri.AbsoluteUri.ToString()).Split('?')[1].Split('&');
                    txtUserNameID.Text = DeCodeString(str[0].Split('=')[1].ToString());
                    pwdPasssword.Password = DeCodeString(str[1].Split('=')[1].ToString());
                    if (str.Length > 2)
                    {
                        txtEmail.Text = DeCodeString(str[2].Split('=')[1].ToString());
                        btnOK_Click(null, null);
                    }
                    else
                    {
                        btnLogIn_Click(null, null);
                    }
                }
                #region Cookies Management

                string strGetCookies = App.GetCookie(BrowserInteropHelper.Source);
                if (strGetCookies != null && strGetCookies != "Login")
                {
                    if (strGetCookies.Split(',').Length > 1)
                    {
                        txtUserNameID.Text = strGetCookies.Split(',')[0];
                        pwdPasssword.Password = strGetCookies.Split(',')[1];
                        btnLogIn_Click(null, null);
                    }
                    //Authenticate();
                }

                #endregion
            }
            catch
            {
            }
		}

		void dispTimer4DomainLoading_Tick(object sender, EventArgs e)
		{
			Authenticate();
		}

		private void txtUserNameID_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
		{
			try
			{
				if (e.Key.Equals(System.Windows.Input.Key.Enter))
				{
					pwdPasssword.Focus();
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "txtUserNameID_KeyDown()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		private void pwdPasssword_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
		{
			try
			{
				if (e.Key.Equals(System.Windows.Input.Key.Enter))
				{
					btnLogIn_Click(new object(), new RoutedEventArgs());
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "pwdPasssword_KeyDown()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		private void chkRememberMe_Checked(object sender, System.Windows.RoutedEventArgs e)
		{
			//if (chkRememberMe.IsChecked == true)
			//{
			//    chkSigninAuto.IsEnabled = true;
			//}
			//else
			//{
			//    chkSigninAuto.IsChecked = false;
			//    chkSigninAuto.IsEnabled = false;
			//}
		}

		private void chkSigninAuto_Checked(object sender, System.Windows.RoutedEventArgs e)
		{

		}

		private void btnForgetPassClick(object sender, System.Windows.RoutedEventArgs e)
		{

		}

		private void btnLogIn_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			try
			{
				txtUserNameID.IsEnabled = false;
				pwdPasssword.IsEnabled = false;
				btnForgetPass.IsEnabled = false;
				btnLogIn.IsEnabled = false;
				btnSignUp.IsEnabled = false;

				//if (chkRememberMe.IsChecked == true)
				//{
				//    RegistryKey MyReg = Registry.CurrentUser.CreateSubKey("Vmukti\\userInfo");
				//    MyReg.SetValue("username", txtUserNameID.Text);
				//    MyReg.SetValue("password", pwdPasssword.Password);
				//    MyReg.SetValue("ischeckedpassword", "true");
				//    MyReg.SetValue("ischeckedAutomatic", (bool)chkSigninAuto.IsChecked);
				//}
				dispTimer4DomainLoading.Start();
				// Authenticate();
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "btnLogIn_Click()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		private void Authenticate()
		{
			lock (this)
			{
				try
				{
					StreamReader sReader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\DomainStatus.txt");
					string strStatus = sReader.ReadToEnd();
					sReader.Close();
					bool isSuperNode = false;
					if (strStatus == "Initializing")
					{
						dispTimer4DomainLoading.Stop();
						lblValidate.Content = "Checking....";
						
                            if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp || VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithNetP2P)
                            {
                                isSuperNode = false;
                            }
                            else if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.BootStrap || VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.SuperNode)
                            {
                                isSuperNode = true;
                            }
						if (VMuktiAPI.VMuktiInfo.MainConnectionString == string.Empty)
						{
							CallBootStrapHTTPJoin();
                           
						}

                       
                        //if (objSuperNodeDataContract.SuperNodeIP != "")
                       
						if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrAuthType == AuthType.SQLAuthentication)
						{
							//if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
							//{
							//    clsBootStrapInfo objBootStrapInfo = new clsBootStrapInfo();
							//    objBootStrapInfo.ConnectionString = VMuktiAPI.VMuktiInfo.MainConnectionString;
							//    objBootStrapInfo.AuthType = VMuktiAPI.AuthType.SQLAuthentication.ToString();
							//    string[] strUserInfo = App.chHttpSuperNodeService.IsAuthorizedUser(objBootStrapInfo, txtUserNameID.Text, pwdPasssword.Password);
							//    if (strUserInfo == null)
							//    {
							//        lblValidate.Content = "CouldNot Connect";
							//        btnForgetPass.IsEnabled = true;
							//        btnLogIn.IsEnabled = true;
							//        btnSignUp.IsEnabled = true;
							//        App.chHttpSuperNodeService.svcUnjoin(txtUserNameID.Text.Trim());
							//        App.objHttpSuperNode.CloseClient<IHttpSuperNodeService>();                                    
							//        return;
							//    }
							//    else if (strUserInfo[0] == "WrongPassword")
							//    {
							//        lblValidate.Content = "Please enter valid password!!";
							//        txtUserNameID.IsEnabled = true;
							//        pwdPasssword.IsEnabled = true;
							//        pwdPasssword.Focus();
							//        App.chHttpSuperNodeService.svcUnjoin(txtUserNameID.Text.Trim());
							//        App.objHttpSuperNode.CloseClient<IHttpSuperNodeService>();
							//        return;
							//    }

							//       else if (strUserInfo[0] == "WrongUserName")
							//    {
							//        lblValidate.Content = "Please enter valid user name!!";
							//        txtUserNameID.IsEnabled = true;
							//        pwdPasssword.IsEnabled = true;
							//        txtUserNameID.Focus();
							//        App.chHttpSuperNodeService.svcUnjoin(txtUserNameID.Text.Trim());
							//        App.objHttpSuperNode.CloseClient<IHttpSuperNodeService>();
							//        return;
							//    }
							//    else
							//    {
							//        foreach (string strRes in strUserInfo)
							//        {
							//            switch (strRes.Split('=')[0])
							//            {
							//                case "ID":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.ID = int.Parse(strRes.Split('=')[1]);
							//                    break;

							//                case "DisplayName":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName = strRes.Split('=')[1];
							//                    break;

							//                case "RoleID":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.RoleID = int.Parse(strRes.Split('=')[1]);
							//                    break;

							//                case "FName":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.FName = strRes.Split('=')[1];
							//                    break;

							//                case "LName":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.LName = strRes.Split('=')[1];
							//                    break;

							//                case "EMail":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.EMail = strRes.Split('=')[1];
							//                    break;

							//                case "PassWord":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.PassWord = strRes.Split('=')[1];
							//                    break;

							//                case "IsActive":
							//                    if (strRes.Split('=')[1].ToLower() == "true")
							//                    {
							//                        VMuktiAPI.VMuktiInfo.CurrentPeer.IsActive = true;
							//                    }
							//                    else if (strRes.Split('=')[1].ToLower() == "false")
							//                    {
							//                        VMuktiAPI.VMuktiInfo.CurrentPeer.IsActive = false;
							//                    }
							//                    break;

							//                case "Status":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.Status = strRes.Split('=')[1];
							//                    break;

							//                case "RoleName":
							//                    VMuktiAPI.VMuktiInfo.CurrentPeer.RoleName = strRes.Split('=')[1];
							//                    break;

							//                default:
							//                    break;
							//            }
							//        }
							//    }
							//}
							//else
                            {
                                // **
                                sb1 = CreateTressInfo();
                                System.Text.StringBuilder sb = new  System.Text.StringBuilder();
                                sb.AppendLine("During Login");
                                sb.AppendLine("User is abot to authorised");
                                sb.AppendLine("Username:" + txtUserNameID.Text);
                                sb.AppendLine("PassWord:" + pwdPasssword.Password);
                                sb.AppendLine(sb1.ToString());
                                ClsLogging.WriteToTresslog(sb);
                                // user is about to authorize.....
                                // username txtUserNameID.Text
                                //passsword  pwdPasssword.Password
                                bool AuthResult = false;
                                VMukti.Business.ClsUser CurrenUser = null;
                                CurrenUser = VMukti.Business.ClsUser.GetByUNamePass(txtUserNameID.Text, pwdPasssword.Password, ref AuthResult);
                                if (CurrenUser == null)
                                {
                                    if (AuthResult)
                                    {
                                        // **
                                        sb1 = CreateTressInfo();
                                        System.Text.StringBuilder sb2 = new System.Text.StringBuilder();
                                        sb2.AppendLine("During Login");
                                        sb2.AppendLine("user has enter worng password" );
                                        sb2.AppendLine("Username:" + txtUserNameID.Text);
                                        sb2.AppendLine("PassWord:" + pwdPasssword.Password);
                                        sb2.AppendLine(sb1.ToString());
                                        ClsLogging.WriteToTresslog(sb2);
                                        // this user has enter worng password txtUserNameID.Text
                                        //passsword  pwdPasssword.Password

                                        lblValidate.Content = "Please enter valid password!!";
                                        txtUserNameID.IsEnabled = true;
                                        pwdPasssword.IsEnabled = true;
                                        pwdPasssword.Focus();
                                    }
                                    else
                                    {
                                        // **
                                        sb1 = CreateTressInfo();
                                        System.Text.StringBuilder sb3 = new System.Text.StringBuilder();
                                        sb3.AppendLine("During Login");
                                        sb3.AppendLine("user has enter worng username");
                                        sb3.AppendLine("Username:" + txtUserNameID.Text);
                                        sb3.AppendLine("PassWord:" + pwdPasssword.Password);
                                        sb3.AppendLine(sb1.ToString());
                                        ClsLogging.WriteToTresslog(sb3);
                                        // this user has enter worng username txtUserNameID.Text
                                        //passsword  pwdPasssword.Password

                                        lblValidate.Content = "Please enter valid user name!!";
                                        txtUserNameID.IsEnabled = true;
                                        pwdPasssword.IsEnabled = true;
                                        txtUserNameID.Focus();
                                    }

                                    //btnForgetPass.IsEnabled = true;
                                    btnLogIn.IsEnabled = true;
                                    btnSignUp.IsEnabled = true;
                                    return;
                                }
                                else
                                {
                                    // **
                                    sb1 = CreateTressInfo();
                                    System.Text.StringBuilder sb4 = new System.Text.StringBuilder();
                                    sb4.AppendLine("During Login");
                                    sb4.AppendLine("U*ser login Successfully");
                                    sb4.AppendLine("Username:" + txtUserNameID.Text);
                                    sb4.AppendLine("PassWord:" + pwdPasssword.Password);
                                    sb4.AppendLine(sb1.ToString());
                                    ClsLogging.WriteToTresslog(sb4);
                                    // Successful login for txtUserNameID.Text

                                    VMuktiAPI.VMuktiInfo.CurrentPeer.ID = CurrenUser.ID;
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName = CurrenUser.DisplayName;
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.RoleID = CurrenUser.RoleID;
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.FName = CurrenUser.FName;
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.LName = CurrenUser.LName;
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.EMail = CurrenUser.EMail;
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.PassWord = CurrenUser.PassWord;
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.IsActive = CurrenUser.IsActive;
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.Status = "Online";
                                    VMuktiAPI.VMuktiInfo.CurrentPeer.RoleName = CurrenUser.RoleName;
                                }
                            }
                            try
                            {                                
                                App.chHttpBootStrapService.svcHttpBSAuthorizedUser(txtUserNameID.Text.Trim(), GetIP4Address(), isSuperNode);
                            }
                            catch (System.ServiceModel.EndpointNotFoundException ex)
                            {
                                ex.Data.Add("My Key", "Authenticate()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
                                ClsException.LogError(ex);
                                ClsException.WriteToErrorLogFile(ex);
                                VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                            }
                            catch (System.ServiceModel.CommunicationException exp)
                            {
                                exp.Data.Add("My Key", "Authenticate()--:--CtlLogin.xaml.cs--:--" + exp.Message + " :--:--");
                                ClsException.LogError(exp);
                                ClsException.WriteToErrorLogFile(exp);
                                VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                            }
							if (VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP != "")
							{
								// App.chHttpSuperNodeService = (IHttpSuperNodeService)App.objHttpSuperNode.OpenClient<IHttpSuperNodeService>("http://" + objSuperNodeDataContract.SuperNodeIP + ":80/HttpSuperNode");
                                try
                                {
                                    // **
                                    sb1 = CreateTressInfo();
                                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                                    sb.AppendLine("Login:");
                                    sb.AppendLine("Opening Supernode Client");
                                    sb.AppendLine("SuperNodeIP:" + VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                                    sb.AppendLine(sb1.ToString());
                                    ClsLogging.WriteToTresslog(sb);
                                    // Opening supernode client : VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP
                                    

                                    App.chHttpSuperNodeService = (IHttpSuperNodeService)App.objHttpSuperNode.OpenClient<IHttpSuperNodeService>("http://" + VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP + ":80/HttpSuperNode");
                                    App.chHttpSuperNodeService.svcJoin(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType.ToString());

                                    // **
                                    sb1 = CreateTressInfo();
                                    System.Text.StringBuilder sb5 = new System.Text.StringBuilder();
                                    sb5.AppendLine("Login:");
                                    sb5.AppendLine("supernode client open successfully.");
                                    sb5.AppendLine("SuperNodeIP:" + VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
                                    sb5.AppendLine(sb1.ToString());
                                    ClsLogging.WriteToTresslog(sb5);
                                    // supernode client open successfully.
                                }
                                catch (System.ServiceModel.EndpointNotFoundException ex)
                                {
                                    ex.Data.Add("My Key", "Authenticate()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
                                    ClsException.LogError(ex);
                                    ClsException.WriteToErrorLogFile(ex);
                                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                                }
                                catch (System.ServiceModel.CommunicationException exp)
                                {
                                    exp.Data.Add("My Key", "Authenticate()--:--CtlLogin.xaml.cs--:--" + exp.Message + " :--:--");
                                    ClsException.LogError(exp);
                                    ClsException.WriteToErrorLogFile(exp);
                                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                                }
								//VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP = objSuperNodeDataContract.SuperNodeIP;
							}
							
                          
							// End changes
							
							if (EntAutherized != null)
							{
								lblValidate.Content = "";
								this.Visibility = Visibility.Collapsed;
								EntAutherized();
								// To Notify Buddylist page and start timers,get buddies etc.
								VMuktiAPI.VMuktiHelper.CallEvent("SucessfulLogin", this, new VMuktiAPI.VMuktiEventArgs());
								//ClsRecordingModule clrRecording = new ClsRecordingModule();
								//clrRecording.SetRecordingFTPDetails("Recording");
							}
						}
						//else if (objBootStrapInfo.AuthType == VMuktiAPI.AuthType.SIPAuthentication.ToString())
						//{
						//    if (objBootStrapInfo.SIPUserNumber != "")
						//    {
						//        objRTCAuthClient = new clsRTCAuthClient(objBootStrapInfo.SIPUserNumber, pwdPasssword.Password, objBootStrapInfo.AuthServerIP);
						//        objRTCAuthClient.EntAuthStatus += new clsRTCAuthClient.DelAuthStatus(objRTCAuthClient_EntAuthStatus);
						//    }
						//    else
						//    {
						//        lblValidate.Content = "Account is not created.";
						//    }
						//}


					}
				}
				catch (Exception ex)
				{
					ex.Data.Add("My Key", "Authenticate()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
					ClsException.LogError(ex);
					ClsException.WriteToErrorLogFile(ex);
					txtUserNameID.IsEnabled = true;
					pwdPasssword.IsEnabled = true;
					btnLogIn.IsEnabled = true;
					btnSignUp.IsEnabled = true;
					//btnCancel.IsEnabled = true;
					lblValidate.Content = "Can not connect to bootstarp server.";
				}


			}
		}

		string GetIP4Address()
		{
			string IP4Address = String.Empty;
			try
			{
				foreach (IPAddress IPA in Dns.GetHostAddresses(System.Net.Dns.GetHostName()))
				{
					if (IPA.AddressFamily.ToString() == "InterNetwork")
					{
						IP4Address = IPA.ToString();
						break;
					}
				}
				return IP4Address;
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "GetIP4Address--:--App.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
				return IP4Address;

			}
		}

		//#region Active Agent Report Service WCF Functions

		//void ActiveAgentReport_EntsvcJoin(string uname)
		//{


		//}

		//void ActiveAgentReport_EntsvcUnJoin(string uname)
		//{
		//    // This Function will implemented on Report part.
		//    //ClsAgentStatus clsAgent = new ClsAgentStatus();
		//    //clsAgent.deleteAgentStatusOnServer(int.Parse(uname));
		//}

		//void ActiveAgentReport_EntsvcSetAgentInfo(clsActive_InActiveAgent objAgentInfo, string uName)
		//{
		//    // This Function will implemented on Report part.
		//    //ClsAgentStatus clsAgent = new ClsAgentStatus();
		//    //clsAgent.setAgentStatusOnServer(objAgentInfo);
		//}

		//void ActiveAgentReport_EntsvcGetAgentInfo(string uname)
		//{
		//    try
		//    {
		//        // This function will implemented on Client part.
		//        if (VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName != uname)
		//        {
		//            ClsAgentStatus clsAgent = new ClsAgentStatus();
		//            clsActive_InActiveAgent clsStatus = clsAgent.getAgentInfo(long.Parse(VMuktiAPI.VMuktiInfo.CurrentPeer.ID.ToString()));
		//            App.chNetP2PBootStrapActiveAgentReportChannel.svcSetAgentInfo(clsStatus, VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName);
		//        }
		//    }
		//    catch (Exception ex)
		//    {
		//        ex.Data.Add("My Key", "ActiveAgentReport_EntsvcGetAgentInfo()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
		//        ClsException.LogError(ex);
		//        ClsException.WriteToErrorLogFile(ex);

		//    }
		//}
		//#endregion
		//#region ActiveCall NetP2P Function
		//void CtlLogin_EntsvcAgentLoggedIn(clsActive_InActiveAgent objAgentInfo)
		//{
		//    //enter the values for active/inactive agent report related stuff to sync database
		//}

		//void CtlLogin_EntsvcUnJoin(string uname)
		//{

		//}       

		//void CtlLogin_EntsvcJoin(string uname)
		//{

		//}
		//#endregion

		void objRTCAuthClient_EntAuthStatus(string strAuthStatus)
		{
			try
			{
				switch (strAuthStatus)
				{
					case "Rejected":
						lblValidate.Content = ("Please enter valid user name or password!!");
						break;

					case "Authorized":
						fncAuthorized();
						break;

					case "InProgress":
						lblValidate.Content = "Login is in progress.";
						break;

					case "Incoming":
						break;

					case "Connected":
						break;

					case "Disconnected":
						break;
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "objRTCAuthClient_EntAuthStatus()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}

		}

		private void fncAuthorized()
		{
			try
			{
				VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName = txtUserNameID.Text;
				VMuktiAPI.VMuktiInfo.CurrentPeer.PassWord = pwdPasssword.Password;
				VMuktiAPI.VMuktiInfo.CurrentPeer.IsActive = true;
				VMuktiAPI.VMuktiInfo.CurrentPeer.Status = "Online";

				if (VMuktiAPI.VMuktiInfo.IsSoftPhone == true)
				{
				}
				else
				{
					#region Pratik

					if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.BootStrap || VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.SuperNode)
					{
						// Changes related to vista
						//objSuperNodeDataContract = App.chHttpBootStrapService.svcHttpBsGetSuperNodeIP(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, VMuktiAPI.VMuktiInfo.CurrentPeer.NodeIPs[0], true);
                        try
                        {
                            objSuperNodeDataContract = App.chHttpBootStrapService.svcHttpBsGetSuperNodeIP(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, GetIP4Address(), true);
                        }
                        catch (System.ServiceModel.EndpointNotFoundException ex)
                        {
                            ex.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
                            ClsException.LogError(ex);
                            ClsException.WriteToErrorLogFile(ex);
                            VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        }
                        catch (System.ServiceModel.CommunicationException exp)
                        {
                            exp.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + exp.Message + " :--:--");
                            ClsException.LogError(exp);
                            ClsException.WriteToErrorLogFile(exp);
                            VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        }
						// end vista changes
						if (objSuperNodeDataContract.SuperNodeIP != "")
						{
                            try
                            {
                                App.chHttpSuperNodeService = (IHttpSuperNodeService)App.objHttpBootStrap.OpenClient<IHttpSuperNodeService>("http://" + objSuperNodeDataContract.SuperNodeIP + ":80/HttpSuperNode");
                                App.chHttpSuperNodeService.svcJoin(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType.ToString());
                            }
                            catch (System.ServiceModel.EndpointNotFoundException ex)
                            {
                                ex.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
                                ClsException.LogError(ex);
                                ClsException.WriteToErrorLogFile(ex);
                                VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                            }
                            catch (System.ServiceModel.CommunicationException exp)
                            {
                                exp.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + exp.Message + " :--:--");
                                ClsException.LogError(exp);
                                ClsException.WriteToErrorLogFile(exp);
                                VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                            }

							if (EntAutherized != null)
							{
								lblValidate.Content = "";
								this.Visibility = Visibility.Collapsed;
								EntAutherized();
							}
						}
					}
					else
					{
						// changes related to vista
                        try
                        {
                            objSuperNodeDataContract = App.chHttpBootStrapService.svcHttpBsGetSuperNodeIP(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, GetIP4Address(), false);
                        }
                        catch (System.ServiceModel.EndpointNotFoundException ex)
                        {
                            ex.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
                            ClsException.LogError(ex);
                            ClsException.WriteToErrorLogFile(ex);
                            VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        }
                        catch (System.ServiceModel.CommunicationException exp)
                        {
                            exp.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + exp.Message + " :--:--");
                            ClsException.LogError(exp);
                            ClsException.WriteToErrorLogFile(exp);
                            VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        }
						// end vista
						if (objSuperNodeDataContract.SuperNodeIP != "")
						{
                            try
                            {
                                App.chHttpSuperNodeService = (IHttpSuperNodeService)App.objHttpBootStrap.OpenClient<IHttpSuperNodeService>("http://" + objSuperNodeDataContract.SuperNodeIP + ":80/HttpSuperNode");
                                App.chHttpSuperNodeService.svcJoin(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType.ToString());
                            }
                            catch (System.ServiceModel.EndpointNotFoundException ex)
                            {
                                ex.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
                                ClsException.LogError(ex);
                                ClsException.WriteToErrorLogFile(ex);
                                VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                            }
                            catch (System.ServiceModel.CommunicationException exp)
                            {
                                exp.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + exp.Message + " :--:--");
                                ClsException.LogError(exp);
                                ClsException.WriteToErrorLogFile(exp);
                                VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                            }

							if (EntAutherized != null)
							{

								lblValidate.Content = "";
								this.Visibility = Visibility.Collapsed;
								EntAutherized();
							}
						}
					}

					#endregion
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "fncAuthorized()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		private void btnSignUp_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			try
			{
				//if (txtUserNameID.Text != "" || pwdPasssword.Password != "")
				//{
				//    ClsUser objUser = new ClsUser();
				//    //if(varState == 0)

				//    //else
				//    //objUser.ID = varID;
				//    objUser.ID = -1;
				//    objUser.DisplayName = txtUserNameID.Text.Trim();
				//    objUser.RoleID = 2;
				//    objUser.FName = txtUserNameID.Text.Trim();
				//    objUser.LName = "";
				//    objUser.EMail = "support@adiance.com";
				//    objUser.PassWord = pwdPasssword.Password.Trim();
				//    objUser.IsActive = true;
				//    objUser.CreatedBy = 1;
				//    objUser.ModifiedBy = 1;

				//    objUser.RatePerHour = 0;
				//    objUser.OverTimeRate = 0;
				//    objUser.DoubleRatePerHour = 0;
				//    objUser.DoubleOverTimeRate = 0;
				//    int retID = objUser.Save();

				//    if (retID == 0)
				//    {
				//        lblValidate.Content = "UserName in Use";
				//        //MessageBox.Show("User With Same Name is Not Alliwed", "-> User", MessageBoxButton.OK, MessageBoxImage.Information);
				//    }
				//    else
				//    {
				//        lblValidate.Content = "User Created Successfully";
				//        txtUserNameID.Text = "";
				//        pwdPasssword.Password = "";
				//        //MessageBox.Show("Record Saved Successfully!!");
				//    }
				//}
				//else
				//{
				//    lblValidate.Content = "UserName Or Password cant left blank";
				//}

				btnLogIn.Visibility = Visibility.Collapsed;
				btnSignUp.Visibility = Visibility.Collapsed;

				Label lblemail = new Label();
				lblemail.Content = "E-mail ID";
				Canvas.SetTop(lblemail, 107);
				Canvas.SetLeft(lblemail, 5);
				lblemail.Name = "lbemail";
				lblemail.Width = 60;
				lblemail.Height = 25;
				cnvMain.Children.Add(lblemail);


				Canvas.SetTop(txtEmail, 132);
				Canvas.SetLeft(txtEmail, 5);
				txtEmail.Name = "txtEmail";
				txtEmail.Width = 134;
				txtEmail.Height = 20;
				cnvMain.Children.Add(txtEmail);

				Button btnOK = new Button();
				Canvas.SetTop(btnOK, 164);
				Canvas.SetLeft(btnOK, 2);
				btnOK.Content = "OK";
				btnOK.Name = "btnok";
				btnOK.Height = 25;
				btnOK.Width = 68;
				cnvMain.Children.Add(btnOK);


				Button btnCancel = new Button();
				Canvas.SetTop(btnCancel, 164);
				Canvas.SetLeft(btnCancel, 74);
				btnCancel.Content = "CANCEL";
				btnCancel.Name = "btncan";
				btnCancel.Height = 25;
				btnCancel.Width = 68;
				cnvMain.Children.Add(btnCancel);

				btnOK.Click += new RoutedEventHandler(btnOK_Click);
				btnCancel.Click += new RoutedEventHandler(btnCancel_Click);

				////++++++++++++++++++
				//btnOK.GotKeyboardFocus += new KeyboardFocusChangedEventHandler(btnOK_Click);
				//btnCancel.GotKeyboardFocus += new KeyboardFocusChangedEventHandler(btnCancel_Click);
				////++++++++++++++++++               
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "btnSignUp_Click()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		void btnOK_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (txtUserNameID.Text != "" && pwdPasssword.Password != "" && txtEmail.Text != "")
				{
                    //++++++++++++++++++
                    string emailStr = txtEmail.Text;
                    int indexAt = emailStr.IndexOf('@');
                    int indexDot = emailStr.IndexOf('.');
                    int lengthEmail = emailStr.Length;
                    string subStrAt = emailStr.Substring(indexAt,1);
                    string subStrDot = emailStr.Substring(indexDot,1);

                    if (indexAt >= 1 && indexDot >= 3 && (indexDot - indexAt) >= 2 && lengthEmail >=5)
                    {
                        ///////////////////
                        ClsUser objUser = new ClsUser();
                        //if(varState == 0)

                        //else
                        //objUser.ID = varID;
                        objUser.ID = -1;
                        objUser.DisplayName = txtUserNameID.Text.Trim();
                        objUser.RoleID = 2;
                        objUser.FName = txtUserNameID.Text.Trim();
                        objUser.LName = "";
                        objUser.EMail = txtEmail.Text;
                        objUser.PassWord = pwdPasssword.Password.Trim();
                        objUser.IsActive = true;
                        objUser.CreatedBy = 1;
                        objUser.ModifiedBy = 1;

                        objUser.RatePerHour = 0;
                        objUser.OverTimeRate = 0;
                        objUser.DoubleRatePerHour = 0;
                        objUser.DoubleOverTimeRate = 0;

                        lblValidate.Content = "Registering....";
                        while (VMuktiAPI.VMuktiInfo.MainConnectionString == string.Empty)
                        {
                            lblValidate.Content = "Registering....";
                        }
                        //if (VMuktiAPI.VMuktiInfo.MainConnectionString == string.Empty)
                        //{

                        //    CallBootStrapHTTPJoin();
                        //}

                        // **
                        sb1 = CreateTressInfo();
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        sb.AppendLine("Login:");
                        sb.AppendLine("Registering new user.");
                        sb.AppendLine("username:" + txtUserNameID.Text);
                        sb.AppendLine("passoword:" + pwdPasssword.Password);
                        sb.AppendLine(sb1.ToString());
                        ClsLogging.WriteToTresslog(sb);
                        // Registering new user
                        // username : txtUserNameID.Text
                        // passoword :  pwdPasssword.Password

                        int retID = objUser.Save();

                        if (retID == 0)
                        {
                            // **
                            sb1 = CreateTressInfo();
                            System.Text.StringBuilder sb6 = new System.Text.StringBuilder();
                            sb6.AppendLine("Login:");
                            sb6.AppendLine("Could not register user.");
                            sb6.AppendLine("username:" + txtUserNameID.Text);
                            sb6.AppendLine("passoword:" + pwdPasssword.Password);
                            sb6.AppendLine(sb1.ToString());
                            ClsLogging.WriteToTresslog(sb6);
                            // Could not register user
                            // username : txtUserNameID.Text
                            // passoword :  pwdPasssword.Password

                            lblValidate.Content = "UserName in Use";
                            //MessageBox.Show("User With Same Name is Not Alliwed", "-> User", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else
                        {
                            // **
                            sb1 = CreateTressInfo();
                            System.Text.StringBuilder sb7 = new System.Text.StringBuilder();
                            sb7.AppendLine("Login:");
                            sb7.AppendLine("user has Registered successfully.");
                            sb7.AppendLine("username:" + txtUserNameID.Text);
                            sb7.AppendLine("passoword:" + pwdPasssword.Password);
                            sb7.AppendLine(sb1.ToString());
                            ClsLogging.WriteToTresslog(sb7);
                            // user has Registered successfully.
                            // username : txtUserNameID.Text
                            // passoword :  pwdPasssword.Password

                            lblValidate.Content = "User Created Successfully";
                            txtUserNameID.Text = "";
                            pwdPasssword.Password = "";
                            txtEmail.Text = "";
                            //MessageBox.Show("Record Saved Successfully!!");
                            for (int i = 0; i < cnvMain.Children.Count; i++)
                            {
                                if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Label")
                                {
                                    if (((Label)cnvMain.Children[i]).Name == "lbemail")
                                    {
                                        cnvMain.Children.RemoveAt(i);
                                    }
                                }

                                if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.TextBox")
                                {
                                    if (((TextBox)cnvMain.Children[i]).Name == "txtEmail")
                                    {
                                        cnvMain.Children.RemoveAt(i);
                                    }
                                }

                                if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Button")
                                {
                                    if (((Button)cnvMain.Children[i]).Name == "btnok")
                                    {
                                        cnvMain.Children.RemoveAt(i);
                                    }
                                }

                                if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Button")
                                {
                                    if (((Button)cnvMain.Children[i]).Name == "btncan")
                                    {
                                        cnvMain.Children.RemoveAt(i);
                                    }
                                }
                            }

                            btnSignUp.Visibility = Visibility.Visible;
                            btnLogIn.Visibility = Visibility.Visible;
                        }
                        ///////////////////
                    }
                    else
                    {
                        lblValidate.Content = "Please Enter a valid Email ID";
                    }

                    //++++++++++++++++++                 
                    
                    
                    
				}
				else
				{
					lblValidate.Content = "UserName Or Password cant left blank";
				}
			}
			catch (Exception ex)
			{
				//MessageBox.Show(ex.Message);
				ex.Data.Add("My Key", "btnOK_Click()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		void btnCancel_Click(object sender, RoutedEventArgs e)
		{
			for (int i = 0; i < cnvMain.Children.Count; i++)
			{
				if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Label")
				{
					if (((Label)cnvMain.Children[i]).Name == "lbemail")
					{
						cnvMain.Children.RemoveAt(i);
					}
				}

				if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.TextBox")
				{
					if (((TextBox)cnvMain.Children[i]).Name == "txtEmail")
					{
						cnvMain.Children.RemoveAt(i);
					}
				}

				if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Button")
				{
					if (((Button)cnvMain.Children[i]).Name == "btnok")
					{
						cnvMain.Children.RemoveAt(i);
					}
				}

				if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Button")
				{
					if (((Button)cnvMain.Children[i]).Name == "btncan")
					{
						cnvMain.Children.RemoveAt(i);
					}
				}
			}

			btnSignUp.Visibility = Visibility.Visible;
			btnLogIn.Visibility = Visibility.Visible;

		}

		void txtEmail_KeyDown(object sender, KeyEventArgs e)
		{
			try
			{
				if(e.Key == Key.Enter)
				{
					btnOK_Click(null,null);
				}
			}
			catch(Exception ex)
			{
				ex.Data.Add("My Key", "txtEmail_KeyDown()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
				//return null;
			}
		}

		static string DeCodeString(string str)
		{
			try
			{
                int j = 0;

                Byte[] encodedBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(str);
                Byte[] ans = new Byte[encodedBytes.Length];
                foreach (Byte b in encodedBytes)
                {

                    int i = Convert.ToInt32(b);

                    if ((i >= 65 && i <= 90) || (i >= 97 && i <= 122))
                    {
                        i -= 4;
                        if ((i < 65 && i >= 61) || (i < 97 && i >= 93))
                            i = i + 26;

                    }
                    else if (i >= 48 && i <= 57)
                    {
                        i -= 7;
                        if (i < 48)
                            i = i + 10;
                    }

                    else
                    {
                        if (i == 61)
                            i = 44;
                        else if (i == 44)
                            i = 61;
                    }

                    ans[j++] = Convert.ToByte(i);
                }
                return System.Text.ASCIIEncoding.ASCII.GetString(ans);
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "DeCodeString()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);
				return null;
			}
			//try
			//{
			//    int j = 0;

			//    Byte[] encodedBytes = ASCIIEncoding.ASCII.GetBytes(str);
			//    Byte[] ans = new Byte[encodedBytes.Length];
			//    foreach (Byte b in encodedBytes)
			//    {

			//        int i = Convert.ToInt32(b);

			//        if ((i >= 65 && i <= 90) || (i >= 97 && i <= 122))
			//        {
			//            i -= 4;
			//            if ((i < 65 && i >= 61) || (i < 97 && i >= 93))
			//                i = i + 26;

			//        }
			//        else if (i >= 48 && i <= 57)
			//        {
			//            i -= 7;
			//            if (i < 48)
			//                i = i + 10;
			//        }

			//        else
			//        {
			//            if (i == 61)
			//                i = 44;
			//            else if (i == 44)
			//                i = 61;
			//        }

			//        ans[j++] = Convert.ToByte(i);
			//    }
			//    return ASCIIEncoding.ASCII.GetString(ans);
			//}
			//catch (Exception exp)
			//{
			//    //exp.Data.Add("My Key", "VideoConferenceEXE--:--Login.xaml.cs--:--Decodestring()--:--");
			//    //clsException.LogError(exp);
			//    //MessageBox.Show(exp.Message);
			//    return null;
			//}
		}

        void CallBootStrapHTTPJoin()
        {
            try
            {
                try
                {
                    clsBootStrapInfo objBootStrapInfo = App.chHttpBootStrapService.svcHttpBSJoin("", null);
                    VMuktiAPI.VMuktiInfo.MainConnectionString = objBootStrapInfo.ConnectionString;

                    switch (objBootStrapInfo.AuthType)
                    {
                        case "SIPAuthentication":
                            VMuktiAPI.VMuktiInfo.CurrentPeer.CurrAuthType = AuthType.SIPAuthentication;
                            break;

                        case "SQLAuthentication":
                            VMuktiAPI.VMuktiInfo.CurrentPeer.CurrAuthType = AuthType.SQLAuthentication;
                            break;

                        default:
                            VMuktiAPI.VMuktiInfo.CurrentPeer.CurrAuthType = AuthType.NotDecided;
                            break;

                    }

                    bool isSuperNode = false;
                    if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp || VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithNetP2P)
                    {
                        isSuperNode = false;
                    }
                    else if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.BootStrap || VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.SuperNode)
                    {
                        isSuperNode = true;
                    }

                    clsSuperNodeDataContract objSuperNodeDataContract = App.chHttpBootStrapService.svcHttpBsGetSuperNodeIP(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, GetIP4Address(), isSuperNode);
                    VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP = objSuperNodeDataContract.SuperNodeIP;
                }
                catch (System.ServiceModel.EndpointNotFoundException ex)
                {
                    ex.Data.Add("My Key", "Authenticate()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
                    ClsException.LogError(ex);
                    ClsException.WriteToErrorLogFile(ex);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                }
                catch (System.ServiceModel.CommunicationException exp)
                {
                    exp.Data.Add("My Key", "Authenticate()--:--CtlLogin.xaml.cs--:--" + exp.Message + " :--:--");
                    ClsException.LogError(exp);
                    ClsException.WriteToErrorLogFile(exp);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                }

            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "CallBootStrapHTTPJoin()--:--CtlLogin.xaml.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }

        }

		#region Registry functions

		void RememberUser()
		{
			//RegistryKey MyReg;

			//MyReg = Registry.CurrentUser.CreateSubKey("Vmukti\\userInfo");
			//string val = ((string)MyReg.GetValue("ischecked"));
			//if (val == "true")
			//{
			//    txtUserNameID.Text = (string)MyReg.GetValue("username");
			//    pwdPasssword.Password = (string)MyReg.GetValue("password");
			//}
		}

		#endregion

		#region IDisposable Members

		public void Dispose()
		{
			//if (dispTmrCheckStatus != null)
			//{
			//    dispTmrCheckStatus = null;
			//}
			if (objRTCAuthClient != null)
			{
				objRTCAuthClient = null;
			}

			if (EntAutherized != null)
			{
				EntAutherized = null;
			}

			if (objSuperNodeDataContract != null)
			{
				objSuperNodeDataContract = null;
			}
			if (txtEmail != null)
			{
				txtEmail = null;
			}
			if (dispTimer4DomainLoading != null)
			{
				dispTimer4DomainLoading = null;
			}
		}

		#endregion

		~CtlLogin()
		{
			Dispose();
		}


        #region logging function

        public static StringBuilder CreateTressInfo()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("User Is : " + VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName);
            sb.AppendLine();
            sb.Append("Peer Type is : " + VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType.ToString());
            sb.AppendLine();
            sb.Append("User's SuperNode is : " + VMuktiAPI.VMuktiInfo.CurrentPeer.SuperNodeIP);
            sb.AppendLine();
            sb.Append("User's Machine Ip Address : " + VMuktiAPI.GetIPAddress.ClsGetIP4Address.GetIP4Address());
            sb.AppendLine();
            sb.AppendLine("----------------------------------------------------------------------------------------");
            return sb;
        }

        #endregion
	}
}